﻿//==================================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 文件名: TrIndagate.cs
// 作 者：代码自动生成
// 日 期：2011-11-8 12:41:14
// 描 述：
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00             
//==================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Text;
using Csla;
using lite;
using Csla.Validation;
using Csla.Data;
using System.Data.SqlClient;
using ZX.DAL;
using OpenExpressApp.ORM;
using ZX.Common;
using System.Reflection;
using ZX.EHR.Library;
using System.Text.RegularExpressions;

namespace ZX.TR.Library
{
	public partial class TrIndagate
	{
        /// <summary>
        /// 验证
        /// </summary>
        /// <returns></returns>
        public override string CheckData()
        {
            if (this.IndagateType == null || this.IndagateType == "")
            {
                return "调研类型不能为空!";
            }
            else if (this.IndagateTopic == null || this.IndagateTopic == "")
            {
                return "调研主题不能为空!";
            }
            else if (this.IndagateContent == null || this.IndagateContent == "")
            {
                return "调研内容不能为空!";
            }
            else if (this.StartTime.ToShortDateString() == "0001-1-1")
            {
                return "开始时间格式不合法!";
            }
            else if (this.EndTime.ToShortDateString() == "0001-1-1")
            {
                return "结束时间格式不合法!";
            }
            else if (!Regex.IsMatch(this.StartTime.ToShortDateString(), @"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$"))
            {
                return "开始时间格式不合法!";
            }
            else if (!Regex.IsMatch(this.EndTime.ToShortDateString(), @"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$"))
            {
                return "结束时间格式不合法!";
            }
            else
            {
                object instance = Reflection.CreateInstance("ZX.TR.Bussiness.BTrSubjectInfo", "ZX.TR.Bussiness");
                Type t = instance.GetType();

                if (this.TrIndagateID == new Guid())
                {
                    object obj = t.InvokeMember("GetIsExist", BindingFlags.Default | BindingFlags.InvokeMethod,
                                    null, instance, new Object[] { this.TrActivityID, this.IndagateType });
                    if ((bool)obj)
                    {
                        return "该活动的调研类型已存在!不能重复添加!";
                    }
                    else
                    {
                        DatUser du = (DatUser)System.Web.HttpContext.Current.Session["User"];
                        this.AddUser = du.UserID;
                        this.Addtime = DateTime.Now;
                    }
                }
                else
                {
                    object obj = t.InvokeMember("GetIndagateCountsByActivityIDAndType", BindingFlags.Default | BindingFlags.InvokeMethod,
                                    null, instance, new Object[] { this.TrActivityID, this.IndagateType });
                    TrIndagate indagate = (TrIndagate)obj;
                    if (indagate != null && indagate.TrIndagateID != this.TrIndagateID)
                    {
                        return "该活动的调研类型已存在!不能重复添加!";
                    }
                    else
                    {
                        DatUser du = (DatUser)System.Web.HttpContext.Current.Session["User"];
                        this.AddUser = du.UserID;
                        this.Addtime = DateTime.Now;
                    }
                }
            }
            return base.CheckData();
        }    

	}
}

